
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>7.记一次基于qiankun的微前端的改造 · Gary的小窝</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Gary">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-solarizedlight.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="git.html" />
    
    
    <link rel="prev" href="ui.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    写在前面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../leetcode/">
            
                <a href="../leetcode/">
            
                    
                    Leetcode之旅
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../leetcode/1.html">
            
                <a href="../leetcode/1.html">
            
                    
                    1.两数之和
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../leetcode/2.html">
            
                <a href="../leetcode/2.html">
            
                    
                    2.两数相加
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../leetcode/3.html">
            
                <a href="../leetcode/3.html">
            
                    
                    3.无重复字符的最长子串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../leetcode/4.html">
            
                <a href="../leetcode/4.html">
            
                    
                    4.寻找两个有序数组的中位数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../leetcode/6.html">
            
                <a href="../leetcode/6.html">
            
                    
                    6.Z字形变换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../leetcode/9.html">
            
                <a href="../leetcode/9.html">
            
                    
                    9.回文数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../leetcode/11.html">
            
                <a href="../leetcode/11.html">
            
                    
                    11.盛最多水的容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../leetcode/12.html">
            
                <a href="../leetcode/12.html">
            
                    
                    12.整数转罗马数字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../leetcode/13.html">
            
                <a href="../leetcode/13.html">
            
                    
                    13.罗马数字转整数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="../leetcode/14.html">
            
                <a href="../leetcode/14.html">
            
                    
                    14.最长公共前缀
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="../leetcode/322.html">
            
                <a href="../leetcode/322.html">
            
                    
                    322.零钱兑换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../leetcode/72.html">
            
                <a href="../leetcode/72.html">
            
                    
                    72.编辑距离
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../flutter/">
            
                <a href="../flutter/">
            
                    
                    Flutter从入门到放弃
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../flutter/dart1.html">
            
                <a href="../flutter/dart1.html">
            
                    
                    1.Dart语言(1)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../flutter/dart2.html">
            
                <a href="../flutter/dart2.html">
            
                    
                    2.Dart语言(2)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../flutter/widget1.html">
            
                <a href="../flutter/widget1.html">
            
                    
                    3.Flutter初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../flutter/containerText.html">
            
                <a href="../flutter/containerText.html">
            
                    
                    4.Container和Text组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../flutter/image.html">
            
                <a href="../flutter/image.html">
            
                    
                    5.Image组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../flutter/chapter2.html">
            
                <a href="../flutter/chapter2.html">
            
                    
                    6.Flutter 技术总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../vue/">
            
                <a href="../vue/">
            
                    
                    Vue组件精讲
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../vue/1.html">
            
                <a href="../vue/1.html">
            
                    
                    1.provide/inject
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../vue/2.html">
            
                <a href="../vue/2.html">
            
                    
                    2.手动实现broadcast和dispatch方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="form.html">
            
                <a href="form.html">
            
                    
                    3.自己动手实现带校验的Form表单组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="./">
            
                <a href="./">
            
                    
                    JavaScript进阶
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="proxy.html">
            
                <a href="proxy.html">
            
                    
                    1.Vue.js 3.0中的响应式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="el.html">
            
                <a href="el.html">
            
                    
                    2.Element UI 源码初探
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="bind.html">
            
                <a href="bind.html">
            
                    
                    3.bind的模拟实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="proto.html">
            
                <a href="proto.html">
            
                    
                    4.JS原型和原型链
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="call.html">
            
                <a href="call.html">
            
                    
                    5.模拟实现call和apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="ui.html">
            
                <a href="ui.html">
            
                    
                    6.使用Vue cli3搭建组件库并发布到 npm
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.7" data-path="microFE.html">
            
                <a href="microFE.html">
            
                    
                    7.记一次基于qiankun的微前端的改造
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="git.html">
            
                <a href="git.html">
            
                    
                    8.Git的使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../vueLibrary/">
            
                <a href="../vueLibrary/">
            
                    
                    基于Vue的PC端的组件库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../vueLibrary/1.html">
            
                <a href="../vueLibrary/1.html">
            
                    
                    1.环境搭建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../life/">
            
                <a href="../life/">
            
                    
                    网事杂谈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../life/1.html">
            
                <a href="../life/1.html">
            
                    
                    1.周杰伦专辑赏析--叶惠美
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../life/2.html">
            
                <a href="../life/2.html">
            
                    
                    2.周杰伦专辑赏析--七里香
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >7.记一次基于qiankun的微前端的改造</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x8BB0;&#x4E00;&#x6B21;&#x57FA;&#x4E8E;qiankun&#x7684;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x5B9E;&#x8DF5;"><b></b>&#x8BB0;&#x4E00;&#x6B21;&#x57FA;&#x4E8E;qiankun&#x7684;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x5B9E;&#x8DF5;</a></li><ul><li><span class="title-icon "></span><a href="#&#x80CC;&#x666F;"><b></b>&#x80CC;&#x666F;</a></li><li><span class="title-icon "></span><a href="#&#x65B9;&#x6848;"><b></b>&#x65B9;&#x6848;</a></li><li><span class="title-icon "></span><a href="#&#x5C55;&#x793A;&#x4EE5;&#x53CA;&#x8FC7;&#x7A0B;"><b></b>&#x5C55;&#x793A;&#x4EE5;&#x53CA;&#x8FC7;&#x7A0B;</a></li><ul><li><span class="title-icon "></span><a href="#&#x7236;&#x9879;&#x76EE;&#x4E2D;"><b></b>&#x7236;&#x9879;&#x76EE;&#x4E2D;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5B50;&#x9879;&#x76EE;"><b></b>&#x5B50;&#x9879;&#x76EE;</a></li><li><span class="title-icon "></span><a href="#&#x603B;&#x7ED3;"><b></b>&#x603B;&#x7ED3;</a></li></ul></ul></div><a href="#&#x8BB0;&#x4E00;&#x6B21;&#x57FA;&#x4E8E;qiankun&#x7684;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x5B9E;&#x8DF5;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="&#x8BB0;&#x4E00;&#x6B21;&#x57FA;&#x4E8E;qiankun&#x7684;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x5B9E;&#x8DF5;"><a name="&#x8BB0;&#x4E00;&#x6B21;&#x57FA;&#x4E8E;qiankun&#x7684;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x5B9E;&#x8DF5;" class="anchor-navigation-ex-anchor" href="#&#x8BB0;&#x4E00;&#x6B21;&#x57FA;&#x4E8E;qiankun&#x7684;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x5B9E;&#x8DF5;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x8BB0;&#x4E00;&#x6B21;&#x57FA;&#x4E8E;qiankun&#x7684;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x5B9E;&#x8DF5;</h1>
<h2 id="&#x80CC;&#x666F;"><a name="&#x80CC;&#x666F;" class="anchor-navigation-ex-anchor" href="#&#x80CC;&#x666F;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x80CC;&#x666F;</h2>
<p>&#x6211;&#x6240;&#x5728;&#x56E2;&#x961F;&#x5728;2019&#x5E74;&#x662F;&#x505A;&#x6574;&#x4E2A;&#x96C6;&#x56E2;&#x4E2D;&#x53F0;&#x7684;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;&#xFF0C;&#x662F;&#x8981;&#x628A;&#x6574;&#x4E2A;&#x96C6;&#x56E2;&#x4E0B;&#x7684;&#x6240;&#x6709;BU&#xFF08;&#x4E1A;&#x52A1;&#x5355;&#x5143;&#xFF09;&#x4E0B;&#x7684;&#x5F88;&#x591A;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;&#x8FDB;&#x884C;&#x6574;&#x5408;&#x5F00;&#x53D1;&#xFF0C;&#x6700;&#x540E;&#x5206;&#x53D1;&#x90E8;&#x7F72;&#x7ED9;&#x5404;&#x4E2A;BU &#x4F7F;&#x7528;&#xFF0C;&#x4ED6;&#x4EEC;&#x4E4B;&#x95F4;&#x6709;&#x7740;&#x4E0D;&#x540C;&#x7684;&#x6743;&#x9650;&#x7CFB;&#x7EDF;&#x3002;</p>
<p>&#x56E0;&#x4E3A;&#x5386;&#x53F2;&#x539F;&#x56E0;&#xFF0C;&#x521A;&#x5F00;&#x59CB;&#x7684;&#x65F6;&#x5019;&#x6240;&#x6709;&#x7684;&#x6A21;&#x5757;&#x90FD;&#x662F;&#x4E00;&#x4E2A;&#x9879;&#x76EE;&#xFF0C;&#x90FD;&#x662F;&#x53EA;&#x6709;&#x4E00;&#x4E2A;html&#x5165;&#x53E3;&#xFF0C;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x5B9E;&#x9645;&#x4E0A;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x83DC;&#x5355;&#xFF0C;&#x6280;&#x672F;&#x6808;&#x662F;Vue&#x5168;&#x5BB6;&#x6876;&#xFF0C;&#x4F7F;&#x7528;&#x7684;&#x662F;&#x82B1;&#x88E4;&#x8869;&#x5927;&#x795E;&#x7684;&#x90A3;&#x4E2A;vue-admin&#x8FDB;&#x884C;&#x7684;&#x6539;&#x9020;&#xFF0C;&#x6240;&#x4EE5;&#x6BCF;&#x5F53;&#x6211;&#x4EEC;&#x5728;&#x8FDB;&#x884C;&#x5F00;&#x53D1;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E00;&#x4E2A;&#x65B0;&#x9879;&#x76EE;&#x4E0A;&#x7EBF;&#xFF0C;&#x7B49;&#x4E8E;&#x8981;&#x91CD;&#x65B0;&#x628A;&#x6240;&#x6709;&#x4EA7;&#x54C1;&#x518D;&#x4E0A;&#x4E00;&#x904D;&#xFF0C;&#x7EF4;&#x62A4;&#x6210;&#x672C;&#x90FD;&#x5F88;&#x9AD8;&#x3002;</p>
<p>&#x540E;&#x6765;&#x4EA7;&#x54C1;&#x63D0;&#x4E86;&#x4E2A;&#x9700;&#x6C42;&#xFF0C;&#x6211;&#x4EEC;&#x8FD9;&#x5957;&#x7CFB;&#x7EDF;&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x6BCF;&#x4E2A;&#x83DC;&#x5355;&#x90FD;&#x53EF;&#x4EE5;&#x62FF;&#x51FA;&#x6765;&#x72EC;&#x7ACB;&#x90E8;&#x7F72;&#x7ED9;&#x5404;&#x4E2A;BU&#x4F7F;&#x7528;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x9009;&#x62E9;&#x5168;&#x90E8;&#x96C6;&#x5408;&#xFF0C;&#x8FD9;&#x6837;&#x5B50;&#x6211;&#x4EEC;&#x73B0;&#x884C;&#x7684;&#x65B9;&#x6848;&#x5C31;&#x4E0D;&#x80FD;&#x7528;&#x4E86;&#xFF0C;&#x9700;&#x8981;&#x518D;&#x8003;&#x8651;&#x5176;&#x4ED6;&#x65B9;&#x6848;&#x3002;</p>
<h2 id="&#x65B9;&#x6848;"><a name="&#x65B9;&#x6848;" class="anchor-navigation-ex-anchor" href="#&#x65B9;&#x6848;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x65B9;&#x6848;</h2>
<p>&#x6211;&#x4EEC;&#x60F3;&#x4E86;&#x51E0;&#x4E2A;&#x65B9;&#x6848;&#xFF0C;&#x4E00;&#x4E2A;&#x662F;iframe&#x7684;&#x65B9;&#x6848;&#xFF0C;&#x628A;&#x6240;&#x6709;&#x5B50;&#x9879;&#x76EE;&#x72EC;&#x7ACB;&#x90E8;&#x7F72;&#xFF0C;&#x4F46;&#x662F;&#x4F1A;&#x6709;&#x5F88;&#x591A;&#x7684;&#x5751;&#x70B9;&#xFF0C;&#x6211;&#x4EEC;&#x8FD9;&#x4E2A;&#x7CFB;&#x7EDF;&#x4E0A;&#x65B9;&#x6709;tab&#x9875;&#x7684;&#x5207;&#x6362;&#xFF0C;&#x662F;&#x8981;&#x6709;&#x7F13;&#x5B58;&#x7684;&#xFF0C;iframe&#x5728;&#x4F60;&#x6253;&#x5F00;&#x4E00;&#x4E2A;&#x9875;&#x9762;&#x7684;&#x65F6;&#x5019;&#x662F;&#x5F53;&#x505A;&#x65B0;&#x9875;&#x9762;&#x6253;&#x5F00;&#x7684; &#x4E0D;&#x4F1A;&#x6709;&#x7F13;&#x5B58;&#x7684;&#x673A;&#x5236;&#xFF0C;&#x8FD8;&#x6709;&#x4E00;&#x4E9B;iframe&#x5176;&#x4ED6;&#x7684;&#x5751;&#x70B9;&#xFF0C;&#x5C31;&#x6CA1;&#x6709;&#x91C7;&#x53D6;iframe&#x7684;&#x65B9;&#x6848;&#x3002;</p>
<p>&#x7B2C;&#x4E8C;&#x4E2A;&#x5C31;&#x662F;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#xFF0C;&#x6700;&#x8FD1;&#x6BD4;&#x8F83;&#x70ED;&#x95E8;&#x7684;&#x4E00;&#x4E2A;&#x8BDD;&#x9898;&#xFF0C;&#x6211;&#x4EEC;&#x67E5;&#x627E;&#x4E86;&#x4E00;&#x4E9B;&#x8D44;&#x6599;&#xFF0C;&#x51B3;&#x5B9A;&#x4F7F;&#x7528;<a href="https://github.com/umijs/qiankun" target="_blank">qiankun</a>&#x8FDB;&#x884C;&#x7ED3;&#x6784;&#x7684;&#x6539;&#x9020;&#xFF0C;&#x6211;&#x4EEC;&#x89C9;&#x5F97;&#x662F;&#x53EF;&#x884C;&#x7684;&#x3002;&#x76EE;&#x524D;&#x6539;&#x9020;&#x5DF2;&#x5B8C;&#x6210;&#xFF0C;&#x6211;&#x4EEC;&#x5B9E;&#x73B0;&#x4E86;&#x4EE5;&#x4E0B;&#x6548;&#x679C;&#xFF1A;</p>
<ul>
<li><p>&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x4E0D;&#x5305;&#x542B;&#x5B50;&#x9879;&#x76EE;&#xFF08;&#x5B50;&#x9879;&#x76EE;&#x6307;&#x7684;&#x662F;&#x90A3;&#x4E2A;&#x5F88;&#x591A;&#x4E2A;&#x83DC;&#x5355;&#x7684;&#xFF09;&#x8D44;&#x6E90;&#x7684;&#x4E3B;&#x9879;&#x76EE;&#xFF0C;&#x4E3B;&#x9879;&#x76EE;&#x53EA;&#x6709;&#x4E00;&#x4E2A;html&#x5165;&#x53E3;&#xFF0C;&#x5B50;&#x9879;&#x76EE;&#x901A;&#x8FC7;&#x4E3B;&#x9879;&#x76EE;&#x6765;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#xFF0C;&#x5B50;&#x7CFB;&#x7EDF;&#x95F4;&#x5207;&#x6362;&#x4E0D;&#x518D;&#x91CD;&#x65B0;&#x52A0;&#x8F7D;&#xFF1B;</p>
</li>
<li><p>&#x83DC;&#x5355;&#x7684;&#x6743;&#x9650;&#x3001;&#x767B;&#x5F55;&#x3001;&#x9000;&#x51FA;&#x7B49;&#x529F;&#x80FD;&#x56E0;&#x4E3A;&#x90FD;&#x662F;&#x5171;&#x7528;&#x4E00;&#x5957;&#x6743;&#x9650;&#x7CFB;&#x7EDF;&#xFF0C;&#x5E76;&#x4E14;&#x628A;&#x767B;&#x9646;&#x4FE1;&#x606F;&#x90FD;&#x5B58;&#x5728;&#x4E86;session&#xFF0C;&#x6240;&#x4EE5;&#x5728;&#x52A0;&#x8F7D;&#x5B50;&#x9879;&#x76EE;&#x7684;&#x65F6;&#x5019;&#x90FD;&#x4E0D;&#x4F1A;&#x5B58;&#x5728;&#x6CA1;&#x6709;&#x6743;&#x9650;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x5728;&#x5FAE;&#x524D;&#x7AEF;&#x4EA4;&#x4E92;&#x4E0B;&#xFF0C;&#x8FD9;&#x4E9B;&#x767B;&#x9646;&#x548C;&#x6743;&#x9650;&#x63A7;&#x5236;&#x90FD;&#x4E0D;&#x4ECE;&#x5B50;&#x9879;&#x76EE;&#x8D70;&#xFF0C;&#x5199;&#x5728;&#x4E3B;&#x9879;&#x76EE;&#x91CC;&#x3002;&#x901A;&#x8FC7;&#x7236;&#x5B50;&#x9879;&#x76EE;&#x7684;&#x901A;&#x4FE1;&#xFF0C;&#x544A;&#x8BC9;&#x5B50;&#x9879;&#x76EE;&#xFF0C;&#x73B0;&#x5728;&#x662F;&#x5728;&#x7236;&#x6846;&#x67B6;&#x4E0B;&#xFF0C;&#x8FD8;&#x662F;&#x72EC;&#x7ACB;&#x90E8;&#x7F72;&#x7684;&#x73AF;&#x5883;&#xFF0C;&#x6765;&#x63A7;&#x5236;&#x662F;&#x5426;&#x663E;&#x793A;&#x5B50;&#x9879;&#x76EE;&#x7684;&#x83DC;&#x5355;&#x680F;&#xFF1B;&#x5982;&#x679C;&#x4EE5;&#x540E;&#x518D;&#x6709;&#x767B;&#x9646;&#xFF0C;&#x6743;&#x9650;&#x7B49;&#x76F8;&#x5173;&#x6539;&#x52A8;&#x53EA;&#x9700;&#x4FEE;&#x6539;&#x4E3B;&#x9879;&#x76EE;&#xFF0C;&#x53EA;&#x9700;&#x5904;&#x7406;&#x4E00;&#x4E2A;&#x4E3B;&#x9879;&#x76EE;&#xFF0C;&#x591A;&#x4E2A;&#x5B50;&#x9879;&#x76EE;&#x53EA;&#x6709;&#x72EC;&#x7ACB;&#x90E8;&#x7F72;&#x7684;&#x65F6;&#x5019;&#x8FDB;&#x884C;&#x5904;&#x7406;&#xFF0C;&#x5728;&#x7236;&#x6846;&#x67B6;&#x5185;&#x4E0D;&#x518D;&#x9700;&#x8981;&#x5904;&#x7406;&#xFF1B;</p>
</li>
<li><p>&#x4EE5;&#x540E;&#x51FA;&#x73B0;&#x65B0;&#x9700;&#x6C42;&#xFF0C;&#x591A;&#x4EBA;&#x5F00;&#x53D1;&#x5B50;&#x9879;&#x76EE;&#x5B50;&#x6A21;&#x5757;&#xFF0C;&#x63A5;&#x5165;&#x4E86;&#x5FAE;&#x524D;&#x7AEF;&#x8FD9;&#x5957;&#x67B6;&#x6784;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x544A;&#x8BC9;&#x7236;&#x6846;&#x67B6;url&#x8DEF;&#x7531;&#xFF0C;&#x8FDB;&#x884C;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x5C31;&#x53EF;&#x4EE5;&#xFF0C;&#x5B50;&#x9879;&#x76EE;&#x5355;&#x72EC;&#x90E8;&#x7F72;&#xFF0C;&#x5F00;&#x53D1;&#x6210;&#x672C;&#x4E5F;&#x6781;&#x5927;&#x7684;&#x964D;&#x4F4E;&#x4E86;&#xFF1B;</p>
</li>
</ul>
<h2 id="&#x5C55;&#x793A;&#x4EE5;&#x53CA;&#x8FC7;&#x7A0B;"><a name="&#x5C55;&#x793A;&#x4EE5;&#x53CA;&#x8FC7;&#x7A0B;" class="anchor-navigation-ex-anchor" href="#&#x5C55;&#x793A;&#x4EE5;&#x53CA;&#x8FC7;&#x7A0B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5C55;&#x793A;&#x4EE5;&#x53CA;&#x8FC7;&#x7A0B;</h2>
<p>&#x6700;&#x540E;&#x7684;&#x6548;&#x679C;&#x80AF;&#x5B9A;&#x770B;&#x4E0A;&#x53BB;&#x548C;&#x4E4B;&#x524D;&#x4E00;&#x6837;</p>
<p><img src="https://imgkr.cn-bj.ufileos.com/bdd427ec-fdac-48de-bdf8-4e6be7224790.png" alt="banner"></p>
<p>&#x9996;&#x5148;&#xFF0C;&#x6211;&#x4EEC;&#x56E2;&#x961F;&#x9996;&#x5148;&#x628A;&#x73B0;&#x5728;&#x6240;&#x6709;&#x96C6;&#x6210;&#x5728;&#x4E00;&#x5957;&#x524D;&#x7AEF;&#x4EE3;&#x7801;&#x7684;&#x5B50;&#x9879;&#x76EE;&#xFF0C;&#x8FDB;&#x884C;&#x4E86;&#x62C6;&#x5206;&#xFF0C;&#x62C6;&#x5206;&#x6210;&#x53EF;&#x4EE5;&#x72EC;&#x7ACB;&#x767B;&#x9646;&#xFF0C;&#x8FD0;&#x884C;&#x7684;&#x5B50;&#x9879;&#x76EE;&#xFF0C;&#x7136;&#x540E;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x9879;&#x76EE;&#xFF0C;&#x628A;&#x4E00;&#x4E9B;&#x767B;&#x5F55;&#x7684;&#x903B;&#x8F91;&#xFF0C;&#x5DE6;&#x4FA7;&#x83DC;&#x5355; &#x8DEF;&#x7531;&#x7B49;&#x4EE3;&#x7801; &#x79FB;&#x690D;&#x8FC7;&#x6765;&#xFF0C;&#x8FD9;&#x4E2A;&#x9879;&#x76EE;&#x4F5C;&#x4E3A;&#x7236;&#x9879;&#x76EE;&#x3002;</p>
<h3 id="&#x7236;&#x9879;&#x76EE;&#x4E2D;"><a name="&#x7236;&#x9879;&#x76EE;&#x4E2D;" class="anchor-navigation-ex-anchor" href="#&#x7236;&#x9879;&#x76EE;&#x4E2D;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x7236;&#x9879;&#x76EE;&#x4E2D;</h3>
<p>&#x6309;&#x7167;qiankun&#x7684;&#x6587;&#x6863;&#xFF0C;&#x7B2C;&#x4E00;&#x6B65;&#x5FC5;&#x987B;&#x6CE8;&#x518C;&#x6240;&#x6709;&#x7684;&#x5B50;&#x9879;&#x76EE;&#xFF08;Create master framework with qiankun&#xFF09;</p>
<p>&#x8FD9;&#x662F;qiankun&#x7684;&#x6587;&#x6863;</p>
<pre class="language-"><code class="lang-js"><span class="token keyword">import</span> <span class="token punctuation">{</span> registerMicroApps<span class="token punctuation">,</span> start <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&apos;qiankun&apos;</span><span class="token punctuation">;</span>

<span class="token keyword">function</span> <span class="token function">render</span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> appContent<span class="token punctuation">,</span> loading <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> container <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">&apos;container&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  ReactDOM<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span><span class="token operator">&lt;</span>Framework loading<span class="token operator">=</span><span class="token punctuation">{</span>loading<span class="token punctuation">}</span> content<span class="token operator">=</span><span class="token punctuation">{</span>appContent<span class="token punctuation">}</span> <span class="token operator">/</span><span class="token operator">&gt;</span><span class="token punctuation">,</span> container<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">function</span> <span class="token function">genActiveRule</span><span class="token punctuation">(</span><span class="token parameter">routerPrefix</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token parameter">location</span> <span class="token operator">=&gt;</span> location<span class="token punctuation">.</span>pathname<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span>routerPrefix<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token function">registerMicroApps</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
  <span class="token punctuation">{</span>
    name<span class="token punctuation">:</span> <span class="token string">&apos;react app&apos;</span><span class="token punctuation">,</span> <span class="token comment">// app name registered</span>
    entry<span class="token punctuation">:</span> <span class="token string">&apos;//localhost:7100&apos;</span><span class="token punctuation">,</span>
    render<span class="token punctuation">,</span>
    activeRule<span class="token punctuation">:</span> <span class="token function">genActiveRule</span><span class="token punctuation">(</span><span class="token string">&apos;/react&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">{</span>
    name<span class="token punctuation">:</span> <span class="token string">&apos;vue app&apos;</span><span class="token punctuation">,</span>
    entry<span class="token punctuation">:</span> <span class="token punctuation">{</span> scripts<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&apos;//localhost:7100/main.js&apos;</span><span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
    render<span class="token punctuation">,</span>
    activeRule<span class="token punctuation">:</span> <span class="token function">genActiveRule</span><span class="token punctuation">(</span><span class="token string">&apos;/vue&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token function">start</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x77E5;&#x9053; &#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x5728;<code>registerMicroApps</code>&#x65B9;&#x6CD5;&#x4E2D;&#x628A;&#x8FD9;&#x4E9B;&#x5B50;&#x9879;&#x76EE;&#x8FDB;&#x884C;&#x58F0;&#x660E;&#xFF0C;&#x540D;&#x79F0; &#x5165;&#x53E3;&#x7B49;&#xFF0C;<code>activeRule</code> &#x662F;&#x4E00;&#x4E2A;bool&#x503C;&#xFF0C;&#x5982;&#x679C;&#x662F;true &#x624D;&#x8868;&#x793A;&#x52A0;&#x8F7D;&#x8FD9;&#x4E2A;&#x5B50;&#x9879;&#x76EE;&#xFF0C;&#x8FD9;&#x65F6;&#x5019;&#x5C31;&#x5F97;&#x81EA;&#x5DF1;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x53BB;&#x5224;&#x65AD;&#x8FD9;&#x4E2A;bool&#x503C;&#x3002; &#x8FD9;&#x4E2A;registerMicroApps&#x65B9;&#x6CD5;&#x8FD8;&#x53EF;&#x4EE5;&#x5E26;&#x4E00;&#x4E9B;&#x53C2;&#x6570;&#x4F20;&#x7ED9;&#x5B50;&#x9879;&#x76EE;&#xFF0C;&#x6211;&#x4EEC;&#x8FD9;&#x8FB9;&#x628A;&#x5F53;&#x524D;&#x7236;&#x6846;&#x67B6;&#x5B9E;&#x4F8B;&#x548C;&#x5224;&#x65AD;&#x662F;&#x5426;&#x5728;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x5185;&#x7684;&#x53D8;&#x91CF;&#x4F20;&#x7ED9;&#x5B50;&#x9879;&#x76EE;&#x3002;</p>
<p>&#x8FD9;&#x4E9B;qiankun&#x7684;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x62BD;&#x6210;&#x4E00;&#x4E2A;&#x7C7B;&#xFF0C;&#x5927;&#x6982;&#x4EE3;&#x7801;&#x5982;&#x4E0B;,&#x56E0;&#x4E3A;qiankun&#x662F;ts&#x5199;&#x7684; &#x6211;&#x4EEC;&#x628A;&#x7236;&#x6846;&#x67B6;&#x7684;&#x4EE3;&#x7801;&#x4E5F;&#x4F7F;&#x7528;&#x7684;ts</p>
<pre class="language-"><code class="lang-js">
<span class="token keyword">import</span> <span class="token punctuation">{</span>
  registerMicroApps<span class="token punctuation">,</span>
  runAfterFirstMounted<span class="token punctuation">,</span>
  start<span class="token punctuation">,</span>
  RegistrableApp
<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&apos;qiankun&apos;</span>

<span class="token keyword">import</span> Vue <span class="token keyword">from</span> <span class="token string">&apos;vue&apos;</span>

<span class="token keyword">export</span> <span class="token keyword">interface</span> <span class="token class-name">AppMap</span> <span class="token punctuation">{</span>
  <span class="token punctuation">[</span>key<span class="token punctuation">:</span> string<span class="token punctuation">]</span><span class="token punctuation">:</span> Vue <span class="token operator">|</span> any
<span class="token punctuation">}</span>

<span class="token keyword">interface</span> <span class="token class-name">Props</span> <span class="token punctuation">{</span>
  <span class="token punctuation">[</span>key<span class="token punctuation">:</span> string<span class="token punctuation">]</span><span class="token punctuation">:</span> any
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">interface</span> <span class="token class-name">RegisterAppsData</span> <span class="token punctuation">{</span>
  name<span class="token punctuation">:</span> string
  localhost<span class="token punctuation">:</span> string
  entry<span class="token punctuation">:</span> string
  activeRule<span class="token punctuation">:</span> string
  props<span class="token operator">?</span><span class="token punctuation">:</span> regProps
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">interface</span> <span class="token class-name">RenderProps</span> <span class="token punctuation">{</span>
  appContent<span class="token punctuation">:</span> string<span class="token punctuation">;</span>
  loading<span class="token punctuation">:</span> boolean<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">interface</span> <span class="token class-name">regProps</span> <span class="token punctuation">{</span>
  isInFramework<span class="token punctuation">:</span> boolean<span class="token punctuation">,</span>
  appCallback<span class="token operator">?</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token parameter">appInstance<span class="token punctuation">:</span> Vue <span class="token operator">|</span> any</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">void</span>

  <span class="token punctuation">[</span>key<span class="token punctuation">:</span> string<span class="token punctuation">]</span><span class="token punctuation">:</span> any
<span class="token punctuation">}</span>

declare module <span class="token string">&apos;vue/types/vue&apos;</span> <span class="token punctuation">{</span>
  <span class="token keyword">interface</span> <span class="token class-name">Vue</span> <span class="token punctuation">{</span>
    $regApp<span class="token punctuation">:</span> RegApp<span class="token punctuation">,</span>
    <span class="token function-variable function">$afterMount</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token parameter">instance<span class="token punctuation">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">void</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">/***
 *
 * @param routerPrefix&#xFF1A; &#x4F20;&#x5165;&#x7684;&#x7528;&#x4E8E;&#x5224;&#x65AD;&#x5B50;&#x5E94;&#x7528;&#x7684;&#x8DEF;&#x7531;
 * @param mode&#xFF1A; &#x6A21;&#x5F0F;&#xFF0C;&#x5B50;&#x5E94;&#x7528;&#x662F;hash&#x6A21;&#x5F0F;&#x8FD8;&#x662F;history&#x6A21;&#x5F0F;
 */</span>
<span class="token keyword">function</span> <span class="token function">genActiveRule</span><span class="token punctuation">(</span>routerPrefix<span class="token punctuation">:</span> string<span class="token punctuation">,</span> mode<span class="token punctuation">:</span> string <span class="token operator">=</span> <span class="token string">&apos;hash&apos;</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token parameter">location<span class="token punctuation">:</span> Location</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> boolean <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token parameter">location<span class="token punctuation">:</span> Location</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>mode <span class="token operator">===</span> <span class="token string">&apos;hash&apos;</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> hash <span class="token operator">=</span> location<span class="token punctuation">.</span>hash<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">&apos;/&apos;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>
      <span class="token keyword">return</span> hash <span class="token operator">===</span> routerPrefix<span class="token punctuation">.</span><span class="token function">substr</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> path <span class="token operator">=</span> location<span class="token punctuation">.</span>hash<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">&apos;/&apos;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>
      <span class="token keyword">return</span> path <span class="token operator">===</span> routerPrefix<span class="token punctuation">.</span><span class="token function">substr</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x7528;&#x4E8E;&#x81EA;&#x52A8;&#x5224;&#x65AD;&#x5F53;&#x524D;&#x8DEF;&#x5F84;&#x662F;&#x5426;&#x662F;dev&#x51E0;&#x6216;pre&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x628A;dev&#x51E0;&#x6216;pre&#x653E;&#x5728;path&#x7684;&#x524D;&#x9762;,&#x5E76;&#x8F93;&#x51FA;//dev.xxx.xxx.com</span>
<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">buildEntry</span><span class="token punctuation">(</span><span class="token parameter">path<span class="token punctuation">:</span> string</span><span class="token punctuation">)</span><span class="token punctuation">:</span> string <span class="token punctuation">{</span>
  <span class="token keyword">const</span> host <span class="token operator">=</span> location<span class="token punctuation">.</span>host
  <span class="token keyword">const</span> hostPrefix <span class="token operator">=</span> host<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">&apos;.&apos;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token comment">// host&#x524D;&#x7F00;</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>host<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">&apos;localhost&apos;</span><span class="token punctuation">)</span> <span class="token operator">||</span> host<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">&apos;127.0.0.1&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">//</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>path<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span>
  <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>hostPrefix<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">&apos;dev&apos;</span><span class="token punctuation">)</span> <span class="token operator">||</span> hostPrefix<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">&apos;test&apos;</span><span class="token punctuation">)</span> <span class="token operator">||</span> hostPrefix<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">&apos;pre&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">//</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>hostPrefix<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">.</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>path<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span>
  <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">//</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>path<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// const test = buildEntry(&apos;pro.s-gsun.com&apos;)</span>
<span class="token comment">// console.log(&apos;test-&gt;&apos;, test)</span>

<span class="token keyword">export</span> <span class="token keyword">class</span> <span class="token class-name">RegApp</span> <span class="token punctuation">{</span>
  <span class="token keyword">public</span> frkInstance<span class="token operator">?</span><span class="token punctuation">:</span> Vue
  <span class="token keyword">public</span> appMap<span class="token punctuation">:</span> AppMap <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
  <span class="token keyword">public</span> curAppInstance<span class="token operator">?</span><span class="token punctuation">:</span> Vue <span class="token operator">|</span> any
  <span class="token comment">// &#x5B50;&#x5E94;&#x7528;&#x7684;&#x6CE8;&#x518C;&#x4FE1;&#x606F;</span>
  <span class="token keyword">public</span> registerAppsData<span class="token operator">!</span><span class="token punctuation">:</span> RegisterAppsData<span class="token punctuation">[</span><span class="token punctuation">]</span>

  <span class="token keyword">public</span> lastContent<span class="token punctuation">:</span> string <span class="token operator">=</span> <span class="token string">&apos;&apos;</span>
  <span class="token keyword">public</span> isStart<span class="token punctuation">:</span> boolean <span class="token operator">=</span> <span class="token boolean">false</span>
  <span class="token keyword">public</span> renderCallback<span class="token operator">!</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token parameter">html<span class="token punctuation">:</span> string</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">void</span>
  <span class="token keyword">public</span> afterMountCallback<span class="token operator">?</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token parameter">instance<span class="token punctuation">:</span> Vue<span class="token punctuation">,</span> props<span class="token punctuation">:</span> Props</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">void</span>
  <span class="token keyword">public</span> afterUnMountCallback<span class="token operator">?</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token parameter">instance<span class="token punctuation">:</span> Vue<span class="token punctuation">,</span> props<span class="token punctuation">:</span> Props</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">void</span>
  <span class="token keyword">public</span> firstMountedCallback<span class="token operator">?</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">void</span>

  <span class="token comment">// &#x6784;&#x9020;&#x51FD;&#x6570;</span>
  <span class="token function">constructor</span><span class="token punctuation">(</span><span class="token parameter">instance<span class="token punctuation">:</span> Vue<span class="token punctuation">,</span> regData<span class="token punctuation">:</span> RegisterAppsData<span class="token punctuation">[</span><span class="token punctuation">]</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>frkInstance <span class="token operator">=</span> instance
    <span class="token keyword">this</span><span class="token punctuation">.</span>registerAppsData <span class="token operator">=</span> regData
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">startApp</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token comment">/***
   *
   * @param appContent &#x5B50;app&#x8BFB;&#x53D6;&#x8FC7;&#x6765;&#x7684;html&#x5185;&#x5BB9;
   * @param loading &#x8BFB;&#x53D6;&#x8FDB;&#x5EA6;&#x6761;&#xFF0C;&#x8BFB;&#x53D6;&#x4E2D;&#x8FD4;&#x56DE;true&#xFF0C;&#x8BFB;&#x53D6;&#x5B8C;&#x6BD5;&#x8FD4;&#x56DE;false
   */</span>
  <span class="token keyword">private</span> <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">{</span> appContent<span class="token punctuation">,</span> loading <span class="token punctuation">}</span><span class="token punctuation">:</span> RenderProps<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">void</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>lastContent <span class="token operator">!==</span> appContent<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span>lastContent <span class="token operator">=</span> appContent
      <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>renderCallback<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">renderCallback</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>lastContent<span class="token punctuation">)</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x56DE;&#x8C03;&#x51FD;&#x6570;</span>
  <span class="token keyword">private</span> <span class="token function">beforeLoad</span><span class="token punctuation">(</span>props<span class="token punctuation">:</span> Props<span class="token punctuation">)</span><span class="token punctuation">:</span> Promise<span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">&gt;</span> <span class="token punctuation">{</span>
    <span class="token comment">// console.log(&apos;before load&apos;, app)</span>
    <span class="token keyword">return</span> Promise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x56DE;&#x8C03;&#x51FD;&#x6570;</span>
  <span class="token keyword">private</span> <span class="token function">beforeMount</span><span class="token punctuation">(</span>props<span class="token punctuation">:</span> Props<span class="token punctuation">)</span><span class="token punctuation">:</span> Promise<span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">&gt;</span> <span class="token punctuation">{</span>
    <span class="token comment">// console.log(&apos;before mount&apos;, app)</span>
    <span class="token keyword">return</span> Promise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// qiankun&#x7684;&#x6302;&#x8F7D;&#x56DE;&#x8C03;</span>
  <span class="token keyword">private</span> afterMount <span class="token operator">=</span> <span class="token punctuation">(</span>props<span class="token punctuation">:</span> Props<span class="token punctuation">)</span><span class="token punctuation">:</span> Promise<span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">&gt;</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token comment">// console.log(`${app.name} afterMount:`, app)</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>afterMountCallback<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">afterMountCallback</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>curAppInstance<span class="token punctuation">,</span> props<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> Promise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// qiankun&#x7684;&#x5378;&#x8F7D;&#x56DE;&#x8C03;</span>
  <span class="token keyword">private</span> afterUnmount <span class="token operator">=</span> <span class="token punctuation">(</span>props<span class="token punctuation">:</span> Props<span class="token punctuation">)</span><span class="token punctuation">:</span> Promise<span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">&gt;</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token comment">// console.log(`${app.name} afterUnmount`, app)</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>afterUnMountCallback<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">afterUnMountCallback</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>curAppInstance<span class="token punctuation">,</span> props<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> Promise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x6CE8;&#x518C;&#x5B50;APP</span>
  <span class="token keyword">private</span> <span class="token function">regApps</span><span class="token punctuation">(</span><span class="token parameter">regData<span class="token punctuation">:</span> RegisterAppsData<span class="token punctuation">[</span><span class="token punctuation">]</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> apps <span class="token operator">=</span> regData<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token parameter">item</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> app<span class="token punctuation">:</span> RegistrableApp<span class="token operator">&lt;</span>Props<span class="token operator">&gt;</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
        name<span class="token punctuation">:</span> item<span class="token punctuation">.</span>name<span class="token punctuation">,</span>
        entry<span class="token punctuation">:</span> process<span class="token punctuation">.</span>env<span class="token punctuation">.</span><span class="token constant">NODE_ENV</span> <span class="token operator">===</span> <span class="token string">&apos;development&apos;</span> <span class="token operator">?</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">//</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>item<span class="token punctuation">.</span>localhost<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span> <span class="token punctuation">:</span> <span class="token function">buildEntry</span><span class="token punctuation">(</span>item<span class="token punctuation">.</span>entry<span class="token punctuation">)</span><span class="token punctuation">,</span>
        render<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        activeRule<span class="token punctuation">:</span> <span class="token function">genActiveRule</span><span class="token punctuation">(</span>item<span class="token punctuation">.</span>activeRule<span class="token punctuation">)</span><span class="token punctuation">,</span>
        props<span class="token punctuation">:</span> <span class="token punctuation">{</span>
          isInFramework<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
          frkInstance<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>frkInstance<span class="token punctuation">,</span>
          <span class="token function-variable function">appCallback</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token parameter">appInstance<span class="token punctuation">:</span> Vue</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>appMap<span class="token punctuation">[</span>item<span class="token punctuation">.</span>name<span class="token punctuation">]</span> <span class="token operator">=</span> appInstance
            <span class="token keyword">this</span><span class="token punctuation">.</span>curAppInstance <span class="token operator">=</span> appInstance
          <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span>
      <span class="token keyword">return</span> app
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token function">registerMicroApps</span><span class="token punctuation">(</span>apps<span class="token punctuation">,</span> <span class="token punctuation">{</span>
      beforeLoad<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>beforeLoad<span class="token punctuation">,</span>
      afterMount<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>afterMount<span class="token punctuation">,</span>
      beforeMount<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>beforeMount<span class="token punctuation">,</span>
      afterUnmount<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>afterUnmount
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token function">runAfterFirstMounted</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>firstMountedCallback<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">firstMountedCallback</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x5F00;&#x59CB;&#x6302;&#x8F7D;-&#x4E00;&#x6B21;&#x6267;&#x884C;</span>
  <span class="token keyword">public</span> <span class="token function">startApp</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token keyword">this</span><span class="token punctuation">.</span>isStart<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;regApp-&gt;&#x5F00;&#x59CB;&apos;</span><span class="token punctuation">)</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">regApps</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>registerAppsData<span class="token punctuation">)</span>
      <span class="token function">start</span><span class="token punctuation">(</span><span class="token punctuation">{</span> jsSandbox<span class="token punctuation">:</span> <span class="token boolean">false</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span>isStart <span class="token operator">=</span> <span class="token boolean">true</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x9996;&#x6B21;&#x6302;&#x5728;&#xFF08;&#x6CA1;&#x4EC0;&#x4E48;&#x5375;&#x7528;&#xFF09;</span>
  <span class="token keyword">public</span> <span class="token function">firstMounted</span><span class="token punctuation">(</span><span class="token function-variable function">callback</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>firstMountedCallback <span class="token operator">=</span> callback
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x5B50;&#x9879;&#x76EE;&#x6E32;&#x67D3;&#x540E;</span>
  <span class="token keyword">public</span> <span class="token function">renderApp</span><span class="token punctuation">(</span><span class="token function-variable function">callback</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token parameter">html<span class="token punctuation">:</span> string</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> any<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>renderCallback <span class="token operator">=</span> callback
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x5B50;&#x9879;&#x76EE;&#x6302;&#x8F7D;&#x540E;</span>
  <span class="token keyword">public</span> <span class="token function">renderAfterMount</span><span class="token punctuation">(</span><span class="token function-variable function">callback</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token parameter">app<span class="token punctuation">:</span> Vue<span class="token punctuation">,</span> props<span class="token punctuation">:</span> Props</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>afterMountCallback <span class="token operator">=</span> callback
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x5B50;&#x9879;&#x76EE;&#x5378;&#x8F7D;&#x540E;</span>
  <span class="token keyword">public</span> <span class="token function">renderAfterUnMount</span><span class="token punctuation">(</span><span class="token function-variable function">callback</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token parameter">app<span class="token punctuation">:</span> Vue<span class="token punctuation">,</span> props<span class="token punctuation">:</span> Props</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>afterUnMountCallback <span class="token operator">=</span> callback
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x83B7;&#x53D6;&#x52A0;&#x8F7D;&#x8FDB;&#x6765;&#x7684;Vue&#x5B9E;&#x5217;</span>
  <span class="token keyword">public</span> <span class="token function">getAppVueInstance</span><span class="token punctuation">(</span><span class="token parameter">appName<span class="token punctuation">:</span> string</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>appMap<span class="token punctuation">[</span>appName<span class="token punctuation">]</span><span class="token punctuation">.</span>instance
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> RegApp
</code></pre>
<p>&#x5B9A;&#x4E49;&#x597D;&#x4E86;&#x8FD9;&#x4E9B;&#x540E;&#x5462;&#xFF0C;&#x5C31;&#x8981;&#x8003;&#x8651;&#x5982;&#x4F55;&#x8C03;&#x7528;&#x4E86;&#xFF0C;&#x6211;&#x4EEC;&#x8FD9;&#x91CC;&#x628A;&#x6240;&#x6709;&#x7684;&#x5B50;&#x9879;&#x76EE;&#x4FE1;&#x606F;&#xFF0C;&#x5B9A;&#x4E49;&#x6210;&#x4E00;&#x4E2A;json&#x6587;&#x4EF6;&#xFF0C;&#x6BCF;&#x6B21;&#x8BFB;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6; &#x53BB;&#x6CE8;&#x518C;&#x5B50;&#x9879;&#x76EE;&#x3002;&#x6211;&#x628A;&#x8FD9;&#x4E9B;&#x6574;&#x4E2A;&#x8FD9;&#x4E9B;&#x529F;&#x80FD; &#x5B9A;&#x4E49;&#x6210;&#x4E00;&#x4E2A;&#x7EC4;&#x4EF6; &#x5728;mian.ts&#x4E2D;&#x53BB;Vue.use&#x5B83;</p>
<pre class="language-"><code class="lang-js"><span class="token comment">//regapi &#x5C31;&#x662F;json&#x6587;&#x4EF6;&#x5730;&#x5740;</span>

axios<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>regApi<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>res<span class="token punctuation">.</span>data<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    Vue<span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span>RegAppPlugin<span class="token punctuation">,</span> <span class="token punctuation">{</span> regData<span class="token punctuation">:</span> res<span class="token punctuation">.</span>data <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token keyword">new</span> <span class="token class-name">Vue</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
      router<span class="token punctuation">,</span>
      store<span class="token punctuation">,</span>
      <span class="token function-variable function">render</span><span class="token punctuation">:</span> <span class="token parameter">h</span> <span class="token operator">=&gt;</span> <span class="token function">h</span><span class="token punctuation">(</span>App<span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">$mount</span><span class="token punctuation">(</span><span class="token string">&apos;#main&apos;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">err</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
<p>&#x8FD9;&#x4E2A; regAppPlugin &#x5C31;&#x662F;&#x5B9A;&#x4E49;&#x7684;index.ts&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;install&#x65B9;&#x6CD5;&#x54AF;</p>
<pre class="language-"><code class="lang-js"><span class="token keyword">import</span> <span class="token punctuation">{</span> VueConstructor <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&apos;vue&apos;</span>
<span class="token keyword">import</span> RegApp <span class="token keyword">from</span> <span class="token string">&apos;./regApp&apos;</span>

<span class="token keyword">const</span> <span class="token function-variable function">install</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">Vue<span class="token punctuation">:</span> VueConstructor<span class="token punctuation">,</span> option<span class="token punctuation">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  <span class="token keyword">let</span> regApp<span class="token operator">!</span><span class="token punctuation">:</span> RegApp

  Vue<span class="token punctuation">.</span><span class="token function">mixin</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    <span class="token function">beforeCreate</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment">// console.log(&apos;this -&gt;&apos;, this)</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>regApp<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        regApp <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">RegApp</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> option<span class="token punctuation">.</span>regData<span class="token punctuation">)</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
  Object<span class="token punctuation">.</span><span class="token function">defineProperty</span><span class="token punctuation">(</span><span class="token class-name">Vue</span><span class="token punctuation">.</span>prototype<span class="token punctuation">,</span> <span class="token string">&apos;$regApp&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
    <span class="token keyword">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> regApp
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  install
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5B9A;&#x4E49;&#x597D;&#x4E86;&#x8FD9;&#x4E9B;&#xFF0C;&#x4F60;&#x5F97;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7EC4;&#x4EF6; &#x53BB;&#x4EE3;&#x8868;&#x4E2D;&#x95F4;&#x7684;content&#x90E8;&#x5206;&#xFF0C;&#x56E0;&#x4E3A;&#x6240;&#x6709;&#x5B50;&#x9879;&#x76EE; &#x90FD;&#x662F;&#x5728;&#x8FD9;&#x4E2A;&#x533A;&#x57DF;&#x5185;&#x8FDB;&#x884C;&#x66FF;&#x6362;&#x7684;&#x3002;&#x5728;&#x8FD9;&#x4E2A;vue&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x6700;&#x91CD;&#x8981;&#x7684;&#x662F;&#x8C03;&#x7528;render&#x65B9;&#x6CD5; &#x53BB;&#x63A5;&#x6536;&#x5185;&#x5BB9; &#x66FF;&#x6362;v-html</p>
<pre class="language-"><code class="lang-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>framework<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token comment">&lt;!--    &lt;p class=&quot;mark&quot;&gt;framwork:&#x5B50;&#x5E94;&#x7528;&#x7684;&#x754C;&#x9762;&lt;/p&gt;--&gt;</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">v-html</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>htmlContent<span class="token punctuation">&quot;</span></span> <span class="token punctuation">/&gt;</span></span>
    <span class="token comment">&lt;!--    &lt;div ref=&quot;appContent&quot;&gt;&lt;/div&gt;--&gt;</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>ts<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
<span class="token keyword">import</span> <span class="token punctuation">{</span> Watch<span class="token punctuation">,</span> Vue <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&apos;vue-property-decorator&apos;</span>
<span class="token keyword">import</span> Component <span class="token keyword">from</span> <span class="token string">&apos;vue-class-component&apos;</span>
<span class="token keyword">import</span> RegApp<span class="token punctuation">,</span> <span class="token punctuation">{</span> AppMap <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&apos;@/plugins/registerMicroApps/regApp&apos;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> Route <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&apos;vue-router&apos;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> ITagView<span class="token punctuation">,</span> TagsViewModule <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&apos;@/store/modules/tags-view&apos;</span>

Component<span class="token punctuation">.</span><span class="token function">registerHooks</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
  <span class="token string">&apos;beforeRouteEnter&apos;</span><span class="token punctuation">,</span>
  <span class="token string">&apos;beforeRouteUpdate&apos;</span><span class="token punctuation">,</span>
  <span class="token string">&apos;beforeRouteLeave&apos;</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span>

@Component
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token keyword">class</span> <span class="token class-name">Framework</span> <span class="token keyword">extends</span> <span class="token class-name">Vue</span> <span class="token punctuation">{</span>
  <span class="token comment">// vue data</span>
  htmlContent<span class="token punctuation">:</span> string <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>regApp<span class="token punctuation">.</span>lastContent
  appMap<span class="token punctuation">:</span> AppMap <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>regApp<span class="token punctuation">.</span>appMap

  <span class="token comment">// curInstance: Vue = this.regApp.curAppInstance</span>

  @<span class="token function">Watch</span><span class="token punctuation">(</span><span class="token string">&apos;$route&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> immediate<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token keyword">private</span> <span class="token function">changeRouter</span><span class="token punctuation">(</span><span class="token parameter">route<span class="token punctuation">:</span> Route</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>

  <span class="token punctuation">}</span>

  <span class="token keyword">get</span> <span class="token function">regApp</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>$regApp
  <span class="token punctuation">}</span>

  <span class="token keyword">get</span> <span class="token function">curInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>regApp<span class="token punctuation">.</span>curAppInstance
  <span class="token punctuation">}</span>

  <span class="token keyword">private</span> <span class="token function">changeTitle</span><span class="token punctuation">(</span><span class="token parameter">app<span class="token punctuation">:</span> Vue</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// debugger</span>
    <span class="token keyword">const</span> item <span class="token operator">=</span> TagsViewModule<span class="token punctuation">.</span>visitedViews<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token parameter">item</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> item<span class="token punctuation">.</span>path <span class="token operator">===</span> app<span class="token punctuation">.</span>$route<span class="token punctuation">.</span>path
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>item<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>item<span class="token punctuation">.</span>meta<span class="token punctuation">.</span>title <span class="token operator">||</span> <span class="token string">&apos;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token string">&apos;&apos;</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        TagsViewModule<span class="token punctuation">.</span><span class="token function">setTagViewMeta</span><span class="token punctuation">(</span>app<span class="token punctuation">.</span>$route<span class="token punctuation">)</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

  <span class="token function">created</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>appMap <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>regApp<span class="token punctuation">.</span>appMap
    <span class="token comment">// this.curInstance = this.regApp.curAppInstance</span>
  <span class="token punctuation">}</span>

  <span class="token function">mounted</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// &#x5B50;&#x9879;&#x76EE;&#x7ED8;&#x5236;&#x91CD;&#x6784;</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>regApp<span class="token punctuation">.</span><span class="token function">renderApp</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">html<span class="token punctuation">:</span> string</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      <span class="token comment">// console.log(&apos;html&#x6E32;&#x67D3;&apos;)</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span>htmlContent <span class="token operator">=</span> html
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>regApp<span class="token punctuation">.</span><span class="token function">renderAfterMount</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">app<span class="token punctuation">,</span> props</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>

    <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>regApp<span class="token punctuation">.</span><span class="token function">renderAfterUnMount</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">app<span class="token punctuation">,</span> props</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>props<span class="token punctuation">.</span>name<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">&#x5B50;&#x9879;&#x76EE;&#x5378;&#x8F7D; -&gt;</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span> app<span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>regApp<span class="token punctuation">.</span><span class="token function">firstMounted</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;&#x9996;&#x6B21;&#x6302;&#x8F7D;&#x5B8C;&#x6210;&apos;</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token comment">// this.regApp.startApp()</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<p>&#x4EE3;&#x7801;&#x4EC5;&#x4F9B;&#x53C2;&#x8003;&#x54C8;</p>
<p>&#x5230;&#x8FD9;&#x91CC; &#x7236;&#x6846;&#x67B6; &#x8981;&#x505A;&#x7684;&#x57FA;&#x672C;&#x5DEE;&#x4E0D;&#x591A;&#x4E86;&#xFF0C;&#x6211;&#x4EEC;&#x6765;&#x770B;&#x539F;&#x6765;&#x7684;&#x5B50;&#x9879;&#x76EE;</p>
<h2 id="&#x5B50;&#x9879;&#x76EE;"><a name="&#x5B50;&#x9879;&#x76EE;" class="anchor-navigation-ex-anchor" href="#&#x5B50;&#x9879;&#x76EE;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B50;&#x9879;&#x76EE;</h2>
<p>&#x5728;&#x5B50;&#x9879;&#x76EE;&#x4E2D;&#xFF0C;&#x6839;&#x636E;qiankun&#x7684;&#x6587;&#x6863; <code>Export the lifecycles from your sub app entry</code></p>
<pre class="language-"><code class="lang-js"><span class="token keyword">export</span> <span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">bootstrap</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;react app bootstraped&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">mount</span><span class="token punctuation">(</span><span class="token parameter">props</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>props<span class="token punctuation">)</span><span class="token punctuation">;</span>
  ReactDOM<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span><span class="token operator">&lt;</span>App <span class="token operator">/</span><span class="token operator">&gt;</span><span class="token punctuation">,</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">&apos;react15Root&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">unmount</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  ReactDOM<span class="token punctuation">.</span><span class="token function">unmountComponentAtNode</span><span class="token punctuation">(</span>document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">&apos;react15Root&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x9700;&#x8981;&#x629B;&#x51FA;&#x6765; &#x8FD9;&#x4E9B;&#x53D8;&#x91CF;
&#x6211;&#x4EEC;&#x5728;&#x8FD9;&#x91CC;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x7C7B;&#x53BB;&#x521D;&#x59CB;&#x5316; &#x5B50;&#x9879;&#x76EE;,&#x4E24;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x4E00;&#x79CD;&#x662F;&#x5728;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x4E0B;&#x7684;&#xFF0C;&#x4E00;&#x79CD;&#x662F;&#x72EC;&#x7ACB;&#x8FD0;&#x884C;&#x7684;,&#x9700;&#x8981;&#x8FDB;&#x884C;&#x5224;&#x65AD;</p>
<pre class="language-"><code class="lang-js"><span class="token comment">//init.js</span>
<span class="token keyword">import</span> Vue <span class="token keyword">from</span> <span class="token string">&apos;vue&apos;</span>
<span class="token keyword">import</span> router <span class="token keyword">from</span> <span class="token string">&apos;./router&apos;</span>
<span class="token keyword">import</span> store <span class="token keyword">from</span> <span class="token string">&apos;./store&apos;</span>
<span class="token keyword">import</span> App <span class="token keyword">from</span> <span class="token string">&apos;./App&apos;</span>

<span class="token keyword">let</span> instance <span class="token operator">=</span> <span class="token keyword">null</span>
<span class="token comment">// const appName = &apos;cd&apos;</span>
<span class="token keyword">const</span> <span class="token function-variable function">init</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">appName</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>window<span class="token punctuation">.</span>isInFramework<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;&#x5B50;&#x5E94;&#x7528;&#x72EC;&#x7ACB;&#x8FD0;&#x884C;&#xFF08;&#x6574;&#x4E2A;&#x9879;&#x76EE;&#x4EC5;&#x6267;&#x884C;&#x4E00;&#x6B21;&#xFF09;&apos;</span><span class="token punctuation">)</span>
    <span class="token class-name">Vue</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>bus <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Vue</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Vue</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
      el<span class="token punctuation">:</span> <span class="token string">&apos;#app&apos;</span><span class="token punctuation">,</span>
      router<span class="token punctuation">,</span>
      store<span class="token punctuation">,</span>
      <span class="token function-variable function">render</span><span class="token punctuation">:</span> <span class="token parameter">h</span> <span class="token operator">=&gt;</span> <span class="token function">h</span><span class="token punctuation">(</span>App<span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">bootstrap</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>appName<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> app bootstraped</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span>

  <span class="token punctuation">}</span>

  <span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">mount</span><span class="token punctuation">(</span><span class="token parameter">props</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>appName<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> props mount -&gt; </span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span> props<span class="token punctuation">)</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>instance<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// &#x628A;&#x7236;&#x6846;&#x67B6;&#x5B9E;&#x4F8B; &#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;bus &#x7ED9;&#x5B50;&#x9879;&#x76EE;&#x7528;</span>
      <span class="token class-name">Vue</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>bus <span class="token operator">=</span> props<span class="token punctuation">.</span>frkInstance
      <span class="token class-name">Vue</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>$frkInstance <span class="token operator">=</span> props<span class="token punctuation">.</span>frkInstance
      <span class="token class-name">Vue</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>$isInFramework <span class="token operator">=</span> props<span class="token punctuation">.</span>isInFramework
      instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Vue</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
        router<span class="token punctuation">,</span>
        store<span class="token punctuation">,</span>
        data<span class="token punctuation">:</span> <span class="token punctuation">{</span>
          isInFramework<span class="token punctuation">:</span> <span class="token boolean">false</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token function-variable function">render</span><span class="token punctuation">:</span> <span class="token parameter">h</span> <span class="token operator">=&gt;</span> <span class="token function">h</span><span class="token punctuation">(</span>App<span class="token punctuation">)</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">$mount</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    props<span class="token punctuation">.</span><span class="token function">appCallback</span><span class="token punctuation">(</span>instance<span class="token punctuation">)</span> <span class="token comment">// &#x4E3B;&#x6846;&#x67B6;&#x4E2D;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x7528;&#x4E8E;&#x5C06;&#x5B50;&#x5E94;&#x7528;&#x7684;&#x5B9E;&#x5217;&#x4F20;&#x5230;&#x4E3B;&#x6846;&#x67B6;</span>
    instance<span class="token punctuation">.</span>isInFramework <span class="token operator">=</span> props<span class="token punctuation">.</span>isInFramework
    <span class="token keyword">const</span> parent <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">&apos;app&apos;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>parentElement
    parent<span class="token punctuation">.</span><span class="token function">replaceChild</span><span class="token punctuation">(</span>instance<span class="token punctuation">.</span>$el<span class="token punctuation">,</span> parent<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">&apos;#app&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">unmount</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>appName<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> unmount</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">return</span> <span class="token punctuation">{</span>
    bootstrap<span class="token punctuation">,</span>
    mount<span class="token punctuation">,</span>
    unmount
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> init
</code></pre>
<p>&#x7136;&#x540E;&#x5728;&#x5B50;&#x9879;&#x76EE; main.js &#x4E2D; &#x53BB;&#x629B;&#x51FA;&#x521A;&#x521A;&#x9700;&#x8981;&#x7684;&#x53D8;&#x91CF;</p>
<pre class="language-"><code class="lang-js"><span class="token keyword">const</span> objInit <span class="token operator">=</span> <span class="token function">init</span><span class="token punctuation">(</span><span class="token string">&apos;project name&apos;</span><span class="token punctuation">)</span>
<span class="token keyword">export</span> <span class="token keyword">const</span> bootstrap <span class="token operator">=</span> objInit<span class="token punctuation">.</span>bootstrap
<span class="token keyword">export</span> <span class="token keyword">const</span> mount <span class="token operator">=</span> objInit<span class="token punctuation">.</span>mount
<span class="token keyword">export</span> <span class="token keyword">const</span> unmount <span class="token operator">=</span> objInit<span class="token punctuation">.</span>unmount
</code></pre>
<h2 id="&#x603B;&#x7ED3;"><a name="&#x603B;&#x7ED3;" class="anchor-navigation-ex-anchor" href="#&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x603B;&#x7ED3;</h2>
<p>&#x5230;&#x8FD9;&#x91CC;&#x57FA;&#x672C;&#x5B8C;&#x6210;&#x4E86; &#x7236;&#x5B50;&#x9879;&#x76EE;&#x7684;&#x642D;&#x5EFA;&#xFF0C;&#x901A;&#x4FE1; &#xFF0C;&#x4E0D;&#x77E5;&#x9053;&#x8FD9;&#x6837;&#x7B97;&#x4E0D;&#x7B97;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x3002;&#x3002;&#x3002;&#x4E0D;&#x8FC7;&#x8FD8;&#x6709;&#x4E00;&#x4E9B;&#x95EE;&#x9898;&#xFF0C;&#x9700;&#x8981;&#x89E3;&#x51B3;&#xFF0C;&#x6BD4;&#x5982;&#x8FD9;&#x4E2A;&#x6846;&#x67B6;&#x4E0A;&#x6709;tab&#x6807;&#x7B7E;&#xFF0C;&#x6807;&#x7B7E;&#x7684;&#x540D;&#x79F0;&#x65F6;&#x52A8;&#x6001;&#x5316;&#x663E;&#x793A;&#x7684;&#xFF0C;&#x9700;&#x8981;&#x7236;&#x5B50;&#x901A;&#x4FE1;&#x7684;&#x65F6;&#x5019;&#x5B50;&#x6846;&#x67B6; &#x4F20;&#x7ED9;&#x7236;&#x6846;&#x67B6;&#xFF0C;&#x73B0;&#x5728;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#x8FD8;&#x4E0D;&#x7B97;&#x4F18;&#x96C5;&#x3002;&#x901A;&#x8FC7;&#x8FD9;&#x4E00;&#x6B21;&#x52A8;&#x624B;&#xFF0C;&#x4E5F;&#x7B97;&#x662F;&#x57FA;&#x672C;&#x5165;&#x4E86;&#x4E2A;&#x95E8;&#x3002;&#x5176;&#x5B9E;qiankun&#x4E5F;&#x662F;&#x57FA;&#x4E8E;single-spa&#x7684;&#x5C01;&#x88C5;&#xFF0C;&#x5176;&#x5B9E;&#x8FD8;&#x662F;&#x5F97;&#x7814;&#x7A76;&#x4E00;&#x4E0B;single-spa&#x90A3;&#x4E2A;&#x9879;&#x76EE; &#x624D;&#x7B97;&#x5403;&#x900F;&#x4E86;&#x5FAE;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#xFF0C;&#x52A0;&#x6CB9;&#x5427;&#x3002;</p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; YoungGary 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2021-09-09 22:08:17
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="ui.html" class="navigation navigation-prev " aria-label="Previous page: 6.使用Vue cli3搭建组件库并发布到 npm">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="git.html" class="navigation navigation-next " aria-label="Next page: 8.Git的使用">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"7.记一次基于qiankun的微前端的改造","level":"1.5.7","depth":2,"next":{"title":"8.Git的使用","level":"1.5.8","depth":2,"path":"js/git.md","ref":"js/git.md","articles":[]},"previous":{"title":"6.使用Vue cli3搭建组件库并发布到 npm","level":"1.5.6","depth":2,"path":"js/ui.md","ref":"js/ui.md","articles":[]},"dir":"ltr"},"config":{"plugins":["theme-comscore","prism","-highlight","copy-code-button","search-pro","-search","-lunr","expandable-chapters","splitter","-sharing","tbfed-pagefooter","anchor-navigation-ex"],"styles":{},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy YoungGary 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prismjs/themes/prism-solarizedlight.css"],"lang":{"shell":"bash"}},"splitter":{},"search-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"theme-comscore":{},"copy-code-button":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"Gary","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Gary的小窝","language":"zh-hans","gitbook":"*","description":"Gary的小窝. 里面包含了个人撰写的技术文章"},"file":{"path":"js/microFE.md","mtime":"2021-09-09T14:08:17.740Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-09-09T14:10:10.930Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

